import React, { Component,PureComponent } from 'react'

export default class Child extends PureComponent {
    state = {
        name: '牛子',
        count: 0
    }
    changeAge = () => {
        this.props.callback(40)
    }
    add=()=>{
        this.setState({
            count:1
        })
        console.log('add执行了');
    }
    constructor(props) {
        super()
        console.log('parent传来的数据', props);
    }
    componentDidMount() {
        // this.timer = setInterval(() => {
        //     this.setState({
        //         count: this.state.count+1
        //     })
        //     console.log(this.state.count);
        // }, 1000)
    }
    // componentDidUpdate(oldprops, oldstate) {
    //     this.state = {
    //         name: '鸡尾'
    //     }
    //     console.log(oldprops, oldstate, this.state);
    // }
    componentWillUnmount(){
        clearInterval(this.timer)
    }
    render() {
        console.log('render执行了');
        let { count } = this.state
        return (
            <div>Child{count}<button onClick={this.changeAge}>1</button> <button onClick={this.add}>加1</button> </div>
        )
    }
}
